/**
 * @param {number[]} nums
 * @return {number}
 */
 var findMin = function(nums) {
    let res = 0, n = nums.length-1
    for(let i = 1 ;i < n; i++){
        if(nums[i]<nums[i-1]&&nums[i]<nums[i+1]){
            res = i
            
        }
    }
    return Math.min(nums[res],nums[0],nums[n])
};

// console.log(findMin([3,4,5,1,2]));


/**
 * @param {number[]} nums
 * @return {number}
 */
//方法2
var findMin = function(nums) {
    let low = 0;
    let high = nums.length - 1;
    while (low < high) {
        const pivot = low + Math.floor((high - low) / 2);
        if (nums[pivot] < nums[high]) {
            high = pivot;
        } else {
            low = pivot + 1;
        }
    }
    return nums[low];
};
